package com.netcracker.training.oracle.main;

import com.netcracker.training.oracle.dao.entity.User;
import com.netcracker.training.oracle.dao.factory.DaoFactory;
import com.netcracker.training.oracle.dao.factory.SQLiteDaoFactory;
import com.netcracker.training.oracle.dao.manager.DBException;
import com.netcracker.training.oracle.dao.manager.DBManager;
import com.netcracker.training.oracle.dao.manager.SQLiteDBManager;
import com.netcracker.training.oracle.dao.user.UserDao;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author olhr0713
 */
public class Lab4 {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(Lab4.class);
    private static final String PATH_TO_DB = "jdbc:sqlite:./db/oracleLabsDB.sqlite";
    
    public static void main(String[] args) {
        try {
            DBManager dBManager = new SQLiteDBManager(PATH_TO_DB);
            DaoFactory daoFactory = new SQLiteDaoFactory(dBManager);
            UserDao userDao = daoFactory.getUserDao();
            
            List<User> userList = userDao.loadAllUsers();
            for (User user: userList){
                LOGGER.info("User Id: [{}], firstName: [{}], secondName: [{}], address: [{}]", 
                        user.getId(), user.getFirstName(), user.getSecondName(), user.getAddress());
            }
        } catch (DBException ex) {
            LOGGER.error("Error work with db",ex);
        }
    }
}